#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<stdlib.h>
#include<assert.h>
using namespace std;

class SeqList
{
public:
	SeqList(int capacity = 10)
	{
		int* arr = (int*)malloc(sizeof(int) * capacity);
		if (arr == NULL)
		{
			perror("malloc fail");
			return;
		}
		_arr = arr;
		_size = 0;
		_capacity = capacity;
	}
		
	void pushback(int n)
	{
		if (_size == _capacity)
		{
			int* arr = (int*)realloc(_arr,sizeof(int) * _capacity * 2);
			if (arr == NULL)
			{
				perror("relloc fail");
				return;
			}
			_arr = arr;
			_capacity = _capacity * 2;
		}
		_arr[_size++] = n;
	}

	int&  operator[](int n)const
	{
		assert(n < _size);

		return  _arr[n];
	}

	const int& size()const
	{
		return _size;
	}

	~SeqList()
	{
		free(_arr);
		_arr = NULL;
		_size = 0;
		_capacity = 0;
	}

private:
	int* _arr;
	int _size;
	int _capacity;
};

void Function(const SeqList& s)
{
	for (int i = 0; i < s.size(); i++)
	{
		cout << s[i] << " ";
	}
}

int main()
{
	SeqList s;
	s.pushback(1);
	s.pushback(2);
	s.pushback(3);
	s.pushback(4);
	s.pushback(5);

	Function(s);

	for (int i = 0; i < s.size(); i++)
	{
		cout << s[i] << " ";
	}

	return 0;
}